#pragma once

#include"Tiles.h"

class CBoard
{
	//Board Variables----------------------------------------------//
private:
	//Mesh---------------------------------------------------------//
	LPD3DXMESH		m_TileMesh;	//Mesh used for the Tiles//
	LPD3DXBUFFER	m_TileTextureData;
	DWORD			m_NumTextures;
	//Textures-----------------------------------------------------//
	LPDIRECT3DTEXTURE9	m_Red,		m_RedSlide,		m_RedStart,		m_RedFinish;
	LPDIRECT3DTEXTURE9	m_Green;
	LPDIRECT3DTEXTURE9	m_Blue,		m_BlueSlide,	m_BlueStart,	m_BlueFinish;
	LPDIRECT3DTEXTURE9	m_Yellow,	m_YellowSlide,	m_YellowStart,	m_YellowFinish;
	LPDIRECT3DTEXTURE9	m_Orange;
	LPDIRECT3DTEXTURE9	m_Purple,	m_PurpleSlide,	m_PurpleStart,	m_PurpleFinish;
	LPDIRECT3DTEXTURE9	m_Grey;
	LPDIRECT3DTEXTURE9	m_Brown;
	//Main Tiles---------------------------------------------------//
	CTile	m_Board[NumberOfTiles];	//All the NORMAL BOARD pieces//
	//Home Stretch Tiles-------------------------------------------//
	CTile	m_HomeStretch0[NumberOfStretch]; //The HOME stretch tiles for player 1//
	CTile	m_HomeStretch1[NumberOfStretch]; //The HOME stretch tiles for player 2//
	CTile	m_HomeStretch2[NumberOfStretch]; //The HOME stretch tiles for player 3//
	CTile	m_HomeStretch3[NumberOfStretch]; //The HOME stretch tiles for player 4//
	//Starting Tiles-----------------------------------------------//
	CSpecialTile	m_Start0;	//The START tile for player 1//
	CSpecialTile	m_Start1;	//The START tile for player 2//
	CSpecialTile	m_Start2;	//The START tile for player 3//
	CSpecialTile	m_Start3;	//The START tile for player 4//
	//Home (Finish) Tiles------------------------------------------//
	CSpecialTile	m_Home0;	//The HOME tile for player 1//
	CSpecialTile	m_Home1;	//The HOME tile for player 2//
	CSpecialTile	m_Home2;	//The HOME tile for player 3//
	CSpecialTile	m_Home3;	//The HOME tile for player 4//

	//Board Functions----------------------------------------------//
public:
	//Constructor//
	CBoard()
	{
		//TODO
	}
	//Destructor//
	~CBoard()
	{
		ReleaseThis(m_TileMesh);
		ReleaseThis(m_TileTextureData);
		ReleaseThis(m_Red);
		ReleaseThis(m_RedStart);
		ReleaseThis(m_RedSlide);
		ReleaseThis(m_RedFinish);
		ReleaseThis(m_Green);
		ReleaseThis(m_Blue);
		ReleaseThis(m_BlueStart);
		ReleaseThis(m_BlueSlide);
		ReleaseThis(m_BlueFinish);
		ReleaseThis(m_Yellow);
		ReleaseThis(m_YellowStart);
		ReleaseThis(m_YellowSlide);
		ReleaseThis(m_YellowFinish);
		ReleaseThis(m_Orange);
		ReleaseThis(m_Purple);
		ReleaseThis(m_PurpleStart)
		ReleaseThis(m_PurpleSlide);
		ReleaseThis(m_PurpleFinish);
		ReleaseThis(m_Grey);
		ReleaseThis(m_Brown);
	}
	void InitBoard(LPDIRECT3DDEVICE9& D3DDevice)
	{
		D3DXLoadMeshFromX(L"Meshes/TileMesh.x", D3DXMESH_MANAGED, D3DDevice,
			NULL, &m_TileTextureData, NULL, &m_NumTextures, &m_TileMesh);

		//Create the Texture that will go on the Tiles//
		D3DXCreateTextureFromFile(D3DDevice, L"Textures/TileRed.jpg",	&m_Red);
		D3DXCreateTextureFromFile(D3DDevice, L"Textures/TileBlue.jpg",	&m_Blue);
		D3DXCreateTextureFromFile(D3DDevice, L"Textures/TileGrey.jpg",	&m_Grey);
		D3DXCreateTextureFromFile(D3DDevice, L"Textures/TileBrown.jpg",	&m_Brown);
		D3DXCreateTextureFromFile(D3DDevice, L"Textures/TileGreen.jpg",	&m_Green);
		D3DXCreateTextureFromFile(D3DDevice, L"Textures/TileYellow.jpg",	&m_Yellow);
		D3DXCreateTextureFromFile(D3DDevice, L"Textures/TileOrange.jpg",	&m_Orange);
		D3DXCreateTextureFromFile(D3DDevice, L"Textures/TilePurple.jpg",	&m_Purple);

		D3DXCreateTextureFromFile(D3DDevice, L"Textures/RedStart.jpg",		&m_RedStart);
		D3DXCreateTextureFromFile(D3DDevice, L"Textures/BlueStart.jpg",		&m_BlueStart);
		D3DXCreateTextureFromFile(D3DDevice, L"Textures/YellowStart.jpg",	&m_YellowStart);
		D3DXCreateTextureFromFile(D3DDevice, L"Textures/PurpleStart.jpg",	&m_PurpleStart);

		D3DXCreateTextureFromFile(D3DDevice, L"Textures/RedSlide.jpg",	&m_RedSlide);
		D3DXCreateTextureFromFile(D3DDevice, L"Textures/BlueSlide.jpg",	&m_BlueSlide);
		D3DXCreateTextureFromFile(D3DDevice, L"Textures/YellowSlide.jpg",&m_YellowSlide);
		D3DXCreateTextureFromFile(D3DDevice, L"Textures/PurpleSlide.jpg",&m_PurpleSlide);

		D3DXCreateTextureFromFile(D3DDevice, L"Textures/RedFinish.jpg",		&m_RedFinish);
		D3DXCreateTextureFromFile(D3DDevice, L"Textures/BlueFinish.jpg",		&m_BlueFinish);
		D3DXCreateTextureFromFile(D3DDevice, L"Textures/YellowFinish.jpg",	&m_YellowFinish);
		D3DXCreateTextureFromFile(D3DDevice, L"Textures/PurpleFinish.jpg",	&m_PurpleFinish);

		m_Board[0].InitTile(				0.0f,		0.0f,			0, 0, 8);
		m_Board[1].InitTile(	     SQUARE_SIZE,		0.0f,			0, 0, 12);
		m_Board[2].InitTile(	2.0f*SQUARE_SIZE,		0.0f,			0, 0, 12);
		m_Board[3].InitTile(	3.0f*SQUARE_SIZE,		0.0f,			0, 0, 12);
		m_Board[4].InitTile(	3.0f*SQUARE_SIZE,		-SQUARE_SIZE,	0, 0, 12);
		m_Board[5].InitTile(	4.0f*SQUARE_SIZE,		-SQUARE_SIZE,	0, 0, 0);
		m_Board[6].InitTile(	5.0f*SQUARE_SIZE,		-SQUARE_SIZE,	0, 0, 4);
		m_Board[7].InitTile(	6.0f*SQUARE_SIZE,		-SQUARE_SIZE,	0, 0, 4);
		m_Board[8].InitTile(	7.0f*SQUARE_SIZE,		-SQUARE_SIZE,	0, 0, 4);
		m_Board[9].InitTile(	8.0f*SQUARE_SIZE,		-SQUARE_SIZE,	0, 0, 8);
		m_Board[10].InitTile(	8.0f*SQUARE_SIZE,	-2.0f*SQUARE_SIZE,	0, 0, 12);
		m_Board[11].InitTile(	8.0f*SQUARE_SIZE,	-3.0f*SQUARE_SIZE,	0, 0, 12);
		m_Board[12].InitTile(	8.0f*SQUARE_SIZE,	-4.0f*SQUARE_SIZE,	0, 0, 1);
		m_Board[13].InitTile(	8.0f*SQUARE_SIZE,	-5.0f*SQUARE_SIZE,	0, 0, 5);
		m_Board[14].InitTile(	8.0f*SQUARE_SIZE,	-6.0f*SQUARE_SIZE,	0, 0, 5);
		m_Board[15].InitTile(	8.0f*SQUARE_SIZE,	-7.0f*SQUARE_SIZE,	0, 0, 9);
		m_Board[16].InitTile(	8.0f*SQUARE_SIZE,	-8.0f*SQUARE_SIZE,	0, 0, 12);
		m_Board[17].InitTile(	7.0f*SQUARE_SIZE,	-8.0f*SQUARE_SIZE,	0, 0, 12);
		m_Board[18].InitTile(	6.0f*SQUARE_SIZE,	-8.0f*SQUARE_SIZE,	0, 0, 12);
		m_Board[19].InitTile(	5.0f*SQUARE_SIZE,	-8.0f*SQUARE_SIZE,	0, 0, 12);
		m_Board[20].InitTile(	5.0f*SQUARE_SIZE,	-9.0f*SQUARE_SIZE,	0, 0, 1);
		m_Board[21].InitTile(	5.0f*SQUARE_SIZE,	-10.0f*SQUARE_SIZE,	0, 0, 5);
		m_Board[22].InitTile(	5.0f*SQUARE_SIZE,	-11.0f*SQUARE_SIZE,	0, 0, 5);
		m_Board[23].InitTile(	5.0f*SQUARE_SIZE,	-12.0f*SQUARE_SIZE,	0, 0, 5);
		m_Board[24].InitTile(	5.0f*SQUARE_SIZE,	-13.0f*SQUARE_SIZE,	0, 0, 9);
		m_Board[25].InitTile(	4.0f*SQUARE_SIZE,	-13.0f*SQUARE_SIZE,	0, 0, 12);
		m_Board[26].InitTile(	3.0f*SQUARE_SIZE,	-13.0f*SQUARE_SIZE,	0, 0, 12);
		m_Board[27].InitTile(	2.0f*SQUARE_SIZE,	-13.0f*SQUARE_SIZE,	0, 0, 2);
		m_Board[28].InitTile(		 SQUARE_SIZE,	-13.0f*SQUARE_SIZE,	0, 0, 6);
		m_Board[29].InitTile(				0.0f,	-13.0f*SQUARE_SIZE,	0, 0, 6);
		m_Board[30].InitTile(		-SQUARE_SIZE,	-13.0f*SQUARE_SIZE,	0, 0, 10);
		m_Board[31].InitTile(		-SQUARE_SIZE,	-12.0f*SQUARE_SIZE,	0, 0, 12);
		m_Board[32].InitTile(		-SQUARE_SIZE,	-11.0f*SQUARE_SIZE,	0, 0, 12);
		m_Board[33].InitTile(		-SQUARE_SIZE,	-10.0f*SQUARE_SIZE,	0, 0, 12);
		m_Board[34].InitTile(	-2.0f*SQUARE_SIZE,	-10.0f*SQUARE_SIZE,	0, 0, 12);
		m_Board[35].InitTile(	-3.0f*SQUARE_SIZE,	-10.0f*SQUARE_SIZE,	0, 0, 2);
		m_Board[36].InitTile(	-4.0f*SQUARE_SIZE,	-10.0f*SQUARE_SIZE,	0, 0, 6);
		m_Board[37].InitTile(	-5.0f*SQUARE_SIZE,	-10.0f*SQUARE_SIZE,	0, 0, 6);
		m_Board[38].InitTile(	-5.0f*SQUARE_SIZE,	-9.0f*SQUARE_SIZE,	0, 0, 6);
		m_Board[39].InitTile(	-6.0f*SQUARE_SIZE,	-9.0f*SQUARE_SIZE,	0, 0, 10);
		m_Board[40].InitTile(	-6.0f*SQUARE_SIZE,	-8.0f*SQUARE_SIZE,	0, 0, 12);
		m_Board[41].InitTile(	-6.0f*SQUARE_SIZE,	-7.0f*SQUARE_SIZE,	0, 0, 12);
		m_Board[42].InitTile(	-5.0f*SQUARE_SIZE,	-7.0f*SQUARE_SIZE,	0, 0, 3);
		m_Board[43].InitTile(	-4.0f*SQUARE_SIZE,	-7.0f*SQUARE_SIZE,	0, 0, 7);
		m_Board[44].InitTile(	-4.0f*SQUARE_SIZE,	-6.0f*SQUARE_SIZE,	0, 0, 7);
		m_Board[45].InitTile(	-4.0f*SQUARE_SIZE,	-5.0f*SQUARE_SIZE,	0, 0, 11);
		m_Board[46].InitTile(	-5.0f*SQUARE_SIZE,	-5.0f*SQUARE_SIZE,	0, 0, 12);
		m_Board[47].InitTile(	-6.0f*SQUARE_SIZE,	-5.0f*SQUARE_SIZE,	0, 0, 12);
		m_Board[48].InitTile(	-7.0f*SQUARE_SIZE,	-5.0f*SQUARE_SIZE,	0, 0, 12);
		m_Board[49].InitTile(	-7.0f*SQUARE_SIZE,	-4.0f*SQUARE_SIZE,	0, 0, 12);
		m_Board[50].InitTile(	-7.0f*SQUARE_SIZE,	-3.0f*SQUARE_SIZE,	0, 0, 3);
		m_Board[51].InitTile(	-7.0f*SQUARE_SIZE,	-2.0f*SQUARE_SIZE,	0, 0, 7);
		m_Board[52].InitTile(	-6.0f*SQUARE_SIZE,	-2.0f*SQUARE_SIZE,	0, 0, 7);
		m_Board[53].InitTile(	-5.0f*SQUARE_SIZE,	-2.0f*SQUARE_SIZE,	0, 0, 7);
		m_Board[54].InitTile(	-4.0f*SQUARE_SIZE,	-2.0f*SQUARE_SIZE,	0, 0, 11);
		m_Board[55].InitTile(	-4.0f*SQUARE_SIZE,		 -SQUARE_SIZE,	0, 0, 12);
		m_Board[56].InitTile(	-4.0f*SQUARE_SIZE,				0.0f,	0, 0, 12);
		m_Board[57].InitTile(	-3.0f*SQUARE_SIZE,				0.0f,	0, 0, 0);
		m_Board[58].InitTile(	-2.0f*SQUARE_SIZE,				0.0f,	0, 0, 4);
		m_Board[59].InitTile(		 -SQUARE_SIZE,				0.0f,	0, 0, 4);

		m_HomeStretch0[0].InitTile(	-2.0f*SQUARE_SIZE,		-SQUARE_SIZE,	0, 4, 12);
		m_HomeStretch0[1].InitTile(	-2.0f*SQUARE_SIZE, -2.0f*SQUARE_SIZE,	0, 4, 12);
		m_HomeStretch0[2].InitTile(	-2.0f*SQUARE_SIZE, -3.0f*SQUARE_SIZE,	0, 4, 12);
		m_HomeStretch0[3].InitTile(		 -SQUARE_SIZE, -3.0f*SQUARE_SIZE,	0, 4, 12);
		m_HomeStretch0[4].InitTile(				 0.0f, -3.0f*SQUARE_SIZE,	0, 4, 12);

		m_HomeStretch1[0].InitTile(	 7.0f*SQUARE_SIZE, -5.0f*SQUARE_SIZE,	0, 5, 12);
		m_HomeStretch1[1].InitTile(	 6.0f*SQUARE_SIZE, -5.0f*SQUARE_SIZE,	0, 5, 12);
		m_HomeStretch1[2].InitTile(	 5.0f*SQUARE_SIZE, -5.0f*SQUARE_SIZE,	0, 5, 12);
		m_HomeStretch1[3].InitTile(	 5.0f*SQUARE_SIZE, -4.0f*SQUARE_SIZE,	0, 5, 12);
		m_HomeStretch1[4].InitTile(	 4.0f*SQUARE_SIZE, -4.0f*SQUARE_SIZE,	0, 5, 12);

		m_HomeStretch2[0].InitTile(		  SQUARE_SIZE, -12.0f*SQUARE_SIZE,	0, 6, 12);
		m_HomeStretch2[1].InitTile(		  SQUARE_SIZE, -11.0f*SQUARE_SIZE,	0, 6, 12);
		m_HomeStretch2[2].InitTile(	 2.0f*SQUARE_SIZE, -11.0f*SQUARE_SIZE,	0, 6, 12);
		m_HomeStretch2[3].InitTile(	 2.0f*SQUARE_SIZE, -10.0f*SQUARE_SIZE,	0, 6, 12);
		m_HomeStretch2[4].InitTile(	 2.0f*SQUARE_SIZE,  -9.0f*SQUARE_SIZE,	0, 6, 12);

		m_HomeStretch3[0].InitTile(	-3.0f*SQUARE_SIZE,  -7.0f*SQUARE_SIZE,	0, 7, 12);
		m_HomeStretch3[1].InitTile(	-3.0f*SQUARE_SIZE,  -8.0f*SQUARE_SIZE,	0, 7, 12);
		m_HomeStretch3[2].InitTile(	-2.0f*SQUARE_SIZE,  -8.0f*SQUARE_SIZE,	0, 7, 12);
		m_HomeStretch3[3].InitTile(		 -SQUARE_SIZE,  -8.0f*SQUARE_SIZE,	0, 7, 12);
		m_HomeStretch3[4].InitTile(				 0.0f,  -8.0f*SQUARE_SIZE,	0, 7, 12);

		m_Start0.InitTile(				0.0f,		SQUARE_SIZE+2.5f,	0, 0, 12);
		m_Start1.InitTile(	9.0f*SQUARE_SIZE+2.5f,	-7.0*SQUARE_SIZE,	0, 1, 12);
		m_Start2.InitTile(		-SQUARE_SIZE,  -14.0*SQUARE_SIZE-2.5f,	0, 2, 12);
		m_Start3.InitTile( -3.0f*SQUARE_SIZE+2.5f,	-5.0*SQUARE_SIZE,	0, 3, 12);

		m_Home0.InitTile(				0.0f,  -4.0f*SQUARE_SIZE-2.5,	0, 8,  12);
		m_Home1.InitTile(	3.0f*SQUARE_SIZE-2.5,  -4.0f*SQUARE_SIZE,	0, 9,  12);
		m_Home2.InitTile(	3.0f*SQUARE_SIZE+2.5,  -9.0f*SQUARE_SIZE,	0, 10, 12);
		m_Home3.InitTile(				0.0f,  -7.0f*SQUARE_SIZE+2.5,	0, 10, 12);
	}

	CTile& GetBoardTile(int tileNumber)
	{
		return m_Board[tileNumber];
	}
	CTile& GetPlayerHomeStretch(int playerNumber, int tileNumber)
	{
		switch(playerNumber)
		{
		case 0: 
			return m_HomeStretch0[tileNumber]; //no need for a break because we are returning//
		case 1: 
			return m_HomeStretch1[tileNumber];
		case 2: 
			return m_HomeStretch2[tileNumber];
		case 3: 
			return m_HomeStretch3[tileNumber];
		default:
			::MessageBoxA(NULL, "Bad Player Number Passed to GetPlayerHomeStretch", "GetPlayerHomeStretch(playerbad)", MB_OK | MB_ICONERROR);
		}
	}
	CSpecialTile GetPlayerStart(int playerNumber)
	{
		switch(playerNumber)
		{
		case 0:
			return m_Start0;
		case 1:
			return m_Start1;
		case 2:
			return m_Start2;
		case 3:
			return m_Start3;
		default:
			::MessageBoxA(NULL, "Bad Player Number Passed to GetPlayerStart", "GetPlayerStart(bad)", MB_OK | MB_ICONERROR);
		}
		return CSpecialTile();
	}
	CSpecialTile GetPlayerHome(int playerNumber)
	{
		switch(playerNumber)
		{
		case 0:
			return m_Home0;
		case 1:
			return m_Home1;
		case 2:
			return m_Home2;
		case 3:
			return m_Home3;
		default:
			::MessageBoxA(NULL, "Bad Player Number Passed to GetPlayerHome", "GetPlayerHome(bad)", MB_OK | MB_ICONERROR);
		}
		return CSpecialTile();
	}

	LPD3DXMESH& getMesh(void)
	{
		return m_TileMesh;
	}

	LPDIRECT3DTEXTURE9& getGreen(void)
	{
		return m_Green;
	}
	LPDIRECT3DTEXTURE9& getHomeTexture(int Player)
	{
		switch(Player)
		{
		case P0:
			return m_Red;
		case P1:
			return m_Purple;
		case P2:
			return m_Blue;
		case P3:
			return m_Yellow;
		}
		return m_Grey;
	}
	LPDIRECT3DTEXTURE9& getHomeStretchTexture(int Player)
	{
		switch(Player)
		{
		case P0:
			return m_Red;
		case P1:
			return m_Purple;
		case P2:
			return m_Blue;
		case P3:
			return m_Yellow;
		}
		return m_Grey;
	}
	LPDIRECT3DTEXTURE9& getStartTexture(int Player)
	{
		switch(Player)
		{
		case P0:
			return m_Red;
		case P1:
			return m_Purple;
		case P2:
			return m_Blue;
		case P3:
			return m_Yellow;
		}
		return m_Grey;
	}
	LPDIRECT3DTEXTURE9& getSlideTexture(int Player)
	{
		switch(Player)
		{
		case START0:
			return m_RedStart;
		case START1:
			return m_PurpleStart;
		case START2:
			return m_BlueStart;
		case START3:
			return m_YellowStart;
		case SLIDE0:
			return m_RedSlide;
		case SLIDE1:
			return m_PurpleSlide;
		case SLIDE2:
			return m_BlueSlide;
		case SLIDE3:
			return m_YellowSlide;
		case FINISH0:
			return m_RedFinish;
		case FINISH1:
			return m_PurpleFinish;
		case FINISH2:
			return m_BlueFinish;
		case FINISH3:
			return m_YellowFinish;
		}
		return m_Grey;
	}
	//added this so I could access the startTiles locations for pawn placment and possible texture location
	D3DXVECTOR3 GetStartLoc(int playerNumber)
	{
		D3DXVECTOR3 pos;
		switch(playerNumber)
		{
		case 0:			
			pos.x = m_Start0.getX();
			pos.z = m_Start0.getZ();
			break;
		case 1:			
			pos.x = m_Start1.getX();
			pos.z = m_Start1.getZ();
			break;
		case 2:		
			pos.x = m_Start2.getX();
			pos.z = m_Start2.getZ();
			break;
		case 3:			
			pos.x = m_Start3.getX();
			pos.z = m_Start3.getZ();
			break;
		default:
			::MessageBoxA(NULL, "Bad Player Number Passed to GetPlayerStart", "GetPlayerStart(bad)", MB_OK | MB_ICONERROR);
		}
		return pos;
	}
	//added this so I could access the homeTiles locations for pawn placment and possible texture location
	D3DXVECTOR3 GetHomeLoc(int playerNumber)
	{
		D3DXVECTOR3 pos;
		switch(playerNumber)
		{
		case 0:			
			pos.x = m_Home0.getX();
			pos.z = m_Home0.getZ();
			break;
		case 1:			
			pos.x = m_Home1.getX();
			pos.z = m_Home1.getZ();
			break;
		case 2:		
			pos.x = m_Home2.getX();
			pos.z = m_Home2.getZ();
			break;
		case 3:			
			pos.x = m_Home3.getX();
			pos.z = m_Home3.getZ();
			break;
		default:
			::MessageBoxA(NULL, "Bad Player Number Passed to GetPlayerStart", "GetPlayerStart(bad)", MB_OK | MB_ICONERROR);
		}
		return pos;
	}
};